package com.dodayum.controller;

import com.alibaba.fastjson.JSON;
import com.dodayum.pojo.User;
import com.dodayum.service.UserService;
import com.dodayum.utils.ResultUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@ResponseBody
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping(value = "/insert")
    public String insert(User user, HttpServletResponse response){
        return JSON.toJSONString("");
    }

    @RequestMapping(value = "user/login")
    public String login(String userName, String password){
        List<User> login = userService.login(userName, password);
        int size = login.size();
        if (size == 1){
            return new ResultUtils(true,null,200,"JSON").buildReturn();
        }else if (size == 0){
            return new ResultUtils(false,"账户名或密码错误",500,"JSON").buildReturn();
        }else {
            return new ResultUtils(false,"有脏数据",500,"JSON").buildReturn();
        }
    }

}
